package gui;

import java.util.List;

import javax.swing.DefaultListCellRenderer;
import javax.swing.DefaultListModel;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JList;

import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import javax.swing.JScrollPane;
import javax.swing.ListSelectionModel;
import javax.swing.border.TitledBorder;

public class RankingPanel extends JPanel
{
	private DefaultListModel<String> model = new DefaultListModel<String>();
	private JList list;

	public RankingPanel()
	{
		setLayout(null);
		setOpaque(false);
		
		JScrollPane scrollPane = new JScrollPane();
		scrollPane.setViewportBorder(new TitledBorder(null, "", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		scrollPane.setBounds(24, 11, 398, 289);
		scrollPane.setBackground(new Color(255,255,255,0));
		scrollPane.setBorder(null);
		add(scrollPane);
		
		list = new JList();
		list.setFont(new Font("Courier New", Font.PLAIN, 13));
		list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
		list.setForeground(Color.WHITE);
		list.setBackground(Color.BLACK);
		scrollPane.setViewportView(list);
	}
	
	public void fillList(List<String> liste)
	{
		list.setModel(model);
		model.removeAllElements();

		for (String m : liste)
		{
			model.addElement(m);
		}

		DefaultListCellRenderer renderer = new DefaultListCellRenderer()
		{
			@Override
			public Component getListCellRendererComponent(JList<?> list,
					Object value, int index, boolean isSelected,
					boolean cellHasFocus)
			{
				Component c = super.getListCellRendererComponent(list, value,
						index, isSelected, cellHasFocus);
				String m = (String) value;
				setText(m);
				return c;
			}
		};
		list.setCellRenderer(renderer);
	}
}
